package com.hrp.hrpdao;

import com.hrp.domain.Jxkhzq;
import com.hrp.domain.TransportRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by Administrator on 2019-04-27.
 */
@Mapper
public interface TransportRecordDao {


    @Select("<script>"
            + " select count(*) total from UIMSS_TRANSPORTRECORD a left join UIMSS_VARIETIES b on a.varietiesId=b.id  where b.showFlag in "
            + "<foreach item='item' index='index' collection='showList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    Integer getTotalCount(@Param("showList") List<Integer> showList);

    @Select("<script>"
            + " select T.* from ( select a.*,ROW_NUMBER() over(order by a.id desc) row from UIMSS_TRANSPORTRECORD a left  join UIMSS_VARIETIES b on   a.varietiesId=b.id where b.showFlag in"
            + "<foreach item='item' index='index' collection='showList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + " ) T  where row in "
            + "<foreach item='item' index='index' collection='strList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<TransportRecord> getTransportRecordByPage(@Param("strList") List<Integer> strList,@Param("showList") List<Integer> showList);

    @Insert("insert into UIMSS_TRANSPORTRECORD(sendTime,varietiesId,varietiesName,supplierId,supplierName,receiverId,receiverName,cph,cmz,csz,jz,jsr,times,memo,price,isSettleAccounts,insertTime,updateTime,czry) values(#{sendTime},#{varietiesId},#{varietiesName},#{supplierId},#{supplierName},#{receiverId} ,#{receiverName},#{cph},#{cmz},#{csz},#{jz},#{jsr},#{times},#{memo},#{price},0,GETDATE(),GETDATE(),#{czry})")
    @Options(useGeneratedKeys=true,keyProperty="id")
    void saveTransportRecordData(TransportRecord transportRecord);


    @Select("select * from UIMSS_TRANSPORTRECORD where id = #{id}")
    TransportRecord getTransportRecordData(@Param("id") Integer id);


    @Update("update  UIMSS_TRANSPORTRECORD set sendTime=#{sendTime},varietiesId=#{varietiesId},varietiesName=#{varietiesName},supplierId=#{supplierId},supplierName=#{supplierName},receiverId=#{receiverId},receiverName=#{receiverName},cph=#{cph},cmz=#{cmz},csz=#{csz},jz=#{jz},jsr=#{jsr},times=#{times},memo=#{memo},price=#{price},updateTime=GETDATE(),czry=#{czry} where id=#{id}")
    Integer updateTransportRecordData(TransportRecord transportRecord);

    //@Update("update  UIMSS_TRANSPORTRECORD set price=#{price} where varietiesId in (#{varietiesIdStr}) and supplierId in (#{supplierIdStr}) and receiverId in (#{receiverIdStr}) and sendTime between #{sendTimeKsrq}  and   #{sendTimeJsrq} ")
    @Update("<script>"
            + " update  UIMSS_TRANSPORTRECORD set price=#{price} where varietiesId in "
            + "<foreach item='item' index='index' collection='varietiesIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + " and  supplierId in "
            + "<foreach item='item' index='index' collection='supplierIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + " and  receiverId in "
            + "<foreach item='item' index='index' collection='receiverIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "  and sendTime between #{sendTimeKsrq}  and   #{sendTimeJsrq}  "
            + "</script>")
    void updateTransportRecordDataPrice(@Param("price") Integer price,@Param("sendTimeKsrq")  String sendTimeKsrq,@Param("sendTimeJsrq")  String sendTimeJsrq,@Param("varietiesIdList") List<Integer> varietiesIdList,@Param("supplierIdList") List<Integer> supplierIdList,@Param("receiverIdList") List<Integer> receiverIdList);



    @Update("<script>"
            + " update  UIMSS_TRANSPORTRECORD set isSettleAccounts=#{isSettleAccounts} where varietiesId in "
            + "<foreach item='item' index='index' collection='varietiesIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + " and  supplierId in "
            + "<foreach item='item' index='index' collection='supplierIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + " and  receiverId in "
            + "<foreach item='item' index='index' collection='receiverIdList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "  and sendTime between #{sendTimeKsrq}  and   #{sendTimeJsrq}  "
            + "</script>")
    void updateIsSettleAccounts(@Param("isSettleAccounts") Integer isSettleAccounts,@Param("sendTimeKsrq")  String sendTimeKsrq,@Param("sendTimeJsrq")  String sendTimeJsrq,@Param("varietiesIdList") List<Integer> varietiesIdList,@Param("supplierIdList") List<Integer> supplierIdList,@Param("receiverIdList") List<Integer> receiverIdList);



}
